package com.itzyf.pokemondata.activity.setting

import android.content.Intent
import cn.jpush.android.api.JPushInterface
import com.avos.avoscloud.AVException
import com.itzyf.pokemondata.R
import com.tydic.baselibrary.activity.BaseActivity
import kotlinx.android.synthetic.main.activity_feedback.*
import com.avos.avoscloud.AVObject
import com.avos.avoscloud.SaveCallback
import com.itzyf.pokemondata.BuildConfig
import com.itzyf.pokemondata.activity.gallery.WebViewActivity


/**
 * @author 依风听雨
 * @version 创建时间：2019/01/11 08:54
 */
class FeedbackActivity : BaseActivity() {
    override fun handlerActivity() {
        btnSubmit.setOnClickListener {
            val feedback = etFeedback.text.toString()
            if (feedback.isEmpty()) {
                showToast("请输入反馈的内容")
                return@setOnClickListener
            }
            showProgressDialog()
            val feedbackObj = AVObject("feedback")// 构建对象
            feedbackObj.put("content", feedback)
            feedbackObj.put("version", BuildConfig.VERSION_NAME)
            feedbackObj.put("registrationID",JPushInterface.getRegistrationID(this))
            feedbackObj.saveInBackground(object : SaveCallback() {
                override fun done(e: AVException?) {
                    if (e != null) {
                        showToast("提交失败：" + e.message)
                        return
                    }
                    showToast("提交成功")
                    etFeedback.setText("")
                    dismissProgressDialog()
                }
            })// 保存到服务端

        }


        tvAbout.setOnClickListener {
            val intent = Intent(this@FeedbackActivity, AboutUsActivity::class.java)
            startActivity(intent)
        }

        tvFeedbackList.setOnClickListener {
            startActivity(Intent(this, FeedbackListActivity::class.java))
        }
    }

    override fun getContentViewId() = R.layout.activity_feedback

    override fun getToolbarTitle() = "意见反馈"

}